home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 45 / Amiga Format CD45 (1999-09)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-11].iso / -serious- / misc / football / user / matchanalysis.rexx < prev    next >
OS/2 REXX Batch file  |  1999-08-16  |  12KB  |  398 lines

  1. /* ***********************************************************************
  2.  
  3.    MATCH ANALYSIS FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       050197   First release.
  11.  1.1       150997   Added code to handle automatic scheduling with dates.
  12.                     As matches are played mid-week, it was better to get
  13.                     all the games in a 7-day period than just reading the
  14.                     Learn file where they are grouped together in the
  15.                     number of teams divide by 2 (some games would be outside
  16.                     this 7-day period). Amended displays.
  17.  1.2       250997   Amended displays of highest/lowest because when using
  18.                     dates, these still gave the week numbers. Routine that
  19.                     calculates the date for the listing is now a callable
  20.                     procedure. Fixed bug where the program expected games
  21.                     to be played every week and added games to weeks that
  22.                     had no games played - the range wasn't incremented
  23.                     enough.
  24.            151297   Tidied display. Added average number of goals per
  25.                     game for highest/lowest.
  26.            310599   Changed to handle extra data in '.sflearn' file.
  27.  
  28. **************************************************************************
  29.  
  30. Procedure
  31. ---------
  32.  
  33. 1. Check files exist. Read Teams.df datafile and store league name.
  34. 2. If automatic scheduling, open Schedule definition file and store
  35.    whether it is run by WEEKS or DATES.
  36. 3. Open Learn file if WEEKS or non-auto sched and get statistics for
  37.    each match for each week. Close file.
  38. 4. Open '.sf' file if DATES and get statistics for each match for each
  39.    week. Increase the range from the start date as the file goes on, adding
  40.    7 days. Close file.
  41. 5. Get the highest and lowest scoring weeks.
  42. 6. Display data and exit.
  43.  
  44. ************************************************************************** */
  45. PARSE ARG league_stuff
  46.  
  47. version      = 1
  48. input_file   = '.df'
  49. input2_file  = '.sflearn'
  50. input3_file  = '.sf'
  51. title        = '*LEAGUE_NAME='
  52. autosched    = '*AUTOSCHD='
  53. separator    = '*'
  54. games.       = '???'
  55. homew.       = '???'
  56. awayw.       = '???'
  57. draws.       = '???'
  58. losses.      = '???'
  59. goalss.      = '???'
  60. weeks        = 0
  61. weekend.     = '???'
  62. months       = "January February March April May June July August September October November December"
  63. not_played   = '__   __'
  64.  
  65.  
  66. parse var league_stuff league_file
  67. league_file = "Data/" || league_file
  68.  
  69. if exists(league_file || input_file) = 0  then exit
  70. if exists(league_file || input2_file) = 0  then exit
  71. if exists(league_file || input3_file) = 0  then exit
  72.  
  73. autos = 0
  74. if open(datafile,league_file || input_file,'r') then do
  75.    do while ~eof(datafile)
  76.       line = readln(datafile)
  77.       if pos(title,line) > 0 then
  78.          league_title = delstr(line,1,13)
  79.       if pos(autosched,line) > 0 then do
  80.          autofile = delstr(line,1,10)
  81.          autos = 1
  82.       end
  83.    end
  84.    close(datafile)
  85. end
  86. else do
  87.    say
  88.    say "ERROR :    (MatchAnalysis)"
  89.    say
  90.    say "Cannot read '"league_file || input_file"' for league name."
  91.    exit
  92. end
  93.  
  94. type = 0
  95. if autos = 1 then do
  96.    if open(datafile,"Data/"||autofile||".schd",'r') then do
  97.       line = readln(datafile)
  98.       if pos("*WEEKS",line) > 0 then
  99.          type = 10
  100.       if pos("*DATES",line) > 0 then do
  101.          type = 20
  102.          start_date = substr(line,8,8)
  103.       end
  104.       close(datafile)
  105.    end
  106.    else do
  107.       say
  108.       say "ERROR :    (MatchAnalysis)"
  109.       say
  110.       say "Cannot read 'Data/"autofile".schd' to check what type of"
  111.       say "schedule it is."
  112.       exit
  113.    end
  114. end
  115.                           /* use this method if its WEEKS or non-auto sched. */
  116. if type < 20 then do
  117.    if open(datafile,league_file || input2_file,'r') then do
  118.       do while ~eof(datafile)
  119.          line = readln(datafile)
  120.          if pos(separator,line) = 0 then do
  121.             if separator = sep then do           /* CHANGE 31/05 */
  122.                weeks = weeks + 1
  123.                sep = ''
  124.                games.weeks = 0
  125.                homew.weeks = 0
  126.                awayw.weeks = 0
  127.                draws.weeks = 0
  128.                losses.weeks = 0
  129.                goalss.weeks = 0
  130.                goals_for = 0
  131.                goals_aga = 0
  132.                goals = 0
  133.             end
  134.             goals_for = strip(substr(line,32,2))
  135.             goals_aga = strip(substr(line,37,2))
  136.             if datatype(goals_for,'n') = 0 | datatype(goals_aga,'n') = 0 then
  137.                leave
  138.             games.weeks = games.weeks + 1
  139.             goalss.weeks = goalss.weeks + goals_for + goals_aga
  140.  
  141.             if goals_for > goals_aga then do
  142.                homew.weeks = homew.weeks + 1
  143.                losses.weeks= losses.weeks + 1
  144.             end
  145.             if goals_for = goals_aga then do
  146.                draws.weeks = draws.weeks + 1
  147.             end
  148.             if goals_for < goals_aga then do
  149.                awayw.weeks = awayw.weeks + 1
  150.                losses.weeks= losses.weeks + 1
  151.             end
  152.          end
  153.          else
  154.             sep = line
  155.       end
  156.       close(datafile)
  157.    end
  158.    else do
  159.       say
  160.       say "ERROR :    (MatchAnalysis)"
  161.       say
  162.       say "Cannot read '"league_file || input2_file"' datafile."
  163.       exit
  164.    end
  165. end                      /* DATES and automatic scheduling */
  166.  
  167. if type = 20 then do
  168.    weeks = 1
  169.    mnth = substr(start_date,3,2)
  170.    ndate= substr(start_date,5,4)||mnth||substr(start_date,1,2)
  171.    range = date('b',ndate,'s')
  172.    range = range + 6
  173.    games.weeks = 0
  174.    weekend.weeks = range
  175.    homew.weeks = 0
  176.    awayw.weeks = 0
  177.    draws.weeks = 0
  178.    losses.weeks = 0
  179.    goalss.weeks = 0
  180.    goals_for = 0
  181.    goals_aga = 0
  182.    goals = 0
  183.    if open(datafile,league_file || input3_file,'r') then do
  184.       do while ~eof(datafile)
  185.          line = readln(datafile)
  186.          if pos(separator,line) > 0 then do
  187.             if pos("*Date:",line) > 0 then do
  188.                year = word(line,5)
  189.                mnth = word(line,4)
  190.                day  = word(line,3)
  191.                cv = 0
  192.                do i=1 to 12
  193.                   if pos(mnth,word(months,i)) > 0 then do
  194.                      cv = i
  195.                      leave
  196.                   end
  197.                end
  198.                sd   = year||right(cv,2,0)||right(day,2,0)
  199.                search_date = date('b',sd,'s')
  200.  
  201.                if search_date > range then do
  202.                   range = range + 7
  203.                   diff  = 1
  204.                                                /* this hopes to skip weeks where no games are played. */
  205.                   do while (diff > 0)
  206.                      diff = search_date - range
  207.                      if diff > 0 then
  208.                         range = range + 7
  209.                   end
  210.  
  211.                   weeks = weeks + 1
  212.                   games.weeks = 0
  213.                   weekend.weeks = range
  214.                   homew.weeks = 0
  215.                   awayw.weeks = 0
  216.                   draws.weeks = 0
  217.                   losses.weeks = 0
  218.                   goalss.weeks = 0
  219.                   goals_for = 0
  220.                   goals_aga = 0
  221.                   goals = 0
  222.                end
  223.             end
  224.          end
  225.          if pos(separator,line) = 0 & pos(not_played,line) = 0 then do
  226.             goals_for = strip(substr(line,32,2))
  227.             goals_aga = strip(substr(line,37,2))
  228.             if datatype(goals_for,'n') > 0 & datatype(goals_aga,'n') > 0 then do
  229.  
  230.                games.weeks = games.weeks + 1
  231.                goalss.weeks = goalss.weeks + goals_for + goals_aga
  232.  
  233.                if goals_for > goals_aga then do
  234.                   homew.weeks = homew.weeks + 1
  235.                   losses.weeks= losses.weeks + 1
  236.                end
  237.                if goals_for = goals_aga then do
  238.                   draws.weeks = draws.weeks + 1
  239.                end
  240.                if goals_for < goals_aga then do
  241.                   awayw.weeks = awayw.weeks + 1
  242.                   losses.weeks= losses.weeks + 1
  243.                end
  244.             end
  245.          end
  246.       end
  247.       close(datafile)
  248.    end
  249.    else do
  250.       say
  251.       say "ERROR :    (MatchAnalysis)"
  252.       say
  253.       say "Cannot read '"league_file || input3_file"' datafile."
  254.       exit
  255.    end
  256. end
  257.  
  258. lowest = 10000
  259. highest= 0
  260. h = 0
  261. l = 0
  262. g = 0
  263. los = 0
  264. losc= 0
  265. hwn = 0
  266. hwnc= 0
  267. awn = 0
  268. awnc= 0
  269. dra = 0
  270. drac= 0
  271. do i=1 to weeks
  272.    if games.i ~= 0 then do
  273.       if goalss.i > highest then do
  274.          highest = goalss.i
  275.          h = i
  276.       end
  277.       if goalss.i < lowest then do
  278.          lowest = goalss.i
  279.          l = i
  280.       end
  281.       g = g + games.i
  282.       if losses.i > los then do
  283.          los = losses.i
  284.          losc= i
  285.       end
  286.       if homew.i > hwn then do
  287.          hwn = homew.i
  288.          hwnc= i
  289.       end
  290.       if awayw.i > awn then do
  291.          awn = awayw.i
  292.          awnc= i
  293.       end
  294.       if draws.i > dra then do
  295.          dra = draws.i
  296.          drac= i
  297.       end
  298.    end
  299. end
  300.  
  301. hgpmwk = 0
  302. lgpmwk = 0
  303. hgpm   = 0
  304. lgpm   = 1000
  305. tscr   = 0
  306.  
  307. do i=1 to weeks
  308.    if games.i ~= 0 then do
  309.       tscr = trunc(goalss.i/games.i,2)
  310.       if tscr > hgpm then do
  311.          hgpm = tscr
  312.          if type < 20 then
  313.             hgpmwk = i
  314.          else
  315.             hgpmwk = weekend.i
  316.       end
  317.       if tscr < lgpm then do
  318.          lgpm = tscr
  319.          if type < 20 then
  320.             lgpmwk = i
  321.          else
  322.             lgpmwk = weekend.i
  323.       end
  324.    end
  325. end
  326.  
  327. say
  328. say center("Match Analysis for '"league_title"'",78)
  329. say "-------------------------------------------------------------------------------"
  330. say
  331. say "Matches Played : "g
  332. say
  333. if type < 20 then do
  334.    say "Highest Number of Home Wins: Week No."hwnc"  with "hwn" wins."
  335.    say "                  Away Wins: Week No."awnc"  with "awn" wins."
  336.    say "                  Losses   : Week No."losc"  with "los" losses."
  337.    say "                  Draws    : Week No."drac"  with "dra" draws."
  338.    say
  339.    say "Highest Scoring: Week No."h"  with "highest" goals."
  340.    say "Lowest Scoring : Week No."l"  with "lowest" goals."
  341.    say
  342.    say "Highest Average Goals Per Match: Week No."hgpmwk"  with "hgpm" goals per match."
  343.    say "Lowest Average Goals Per Match : Week No."lgpmwk"  with "lgpm" goals per match."
  344. end
  345. else do
  346.    say "Highest Number of Home Wins: Week ending '"getweek(weekend.hwnc)"'  with "hwn" wins."
  347.    say "                  Away Wins: Week ending '"getweek(weekend.awnc)"'  with "awn" wins."
  348.    say "                  Losses   : Week ending '"getweek(weekend.losc)"'  with "los" losses."
  349.    say "                  Draws    : Week ending '"getweek(weekend.drac)"'  with "dra" draws."
  350.    say
  351.    say "Highest Scoring: Week ending '"getweek(weekend.h)"'  with "highest" goals."
  352.    say "Lowest Scoring : Week ending '"getweek(weekend.l)"'  with "lowest" goals."
  353.    say
  354.    say "Highest Average Goals Per Match: Week ending '"getweek(hgpmwk)"'  with "hgpm" goals per match."
  355.    say "Lowest Average Goals Per Match : Week ending '"getweek(lgpmwk)"'  with "lgpm" goals per match."
  356. end
  357. say
  358. say
  359. if type < 20 then do
  360.    say "Week No.    Games        Wins                          Goals"
  361.    say "            Played    Home  Away    Draws    Losses    Scored"
  362. end
  363. else do
  364.    say "Week        Games        Wins                          Goals"
  365.    say "Ending      Played    Home  Away    Draws    Losses    Scored"
  366. end
  367. say "---------   ------    ----------    -----    ------    ------"
  368. say
  369. if type < 20 then do
  370.    do i=1 to weeks
  371.       if games.i ~= 0 then
  372.          say "  "left(i,6)"      "left(games.i,4)"     "left(homew.i,3)"   "left(awayw.i,3)"     "left(draws.i,4)"     "left(losses.i,5)"     "left(goalss.i,5)
  373.    end
  374. end
  375. if type = 20 then do
  376.    do i=1 to weeks
  377.       if games.i ~= 0 then do
  378.          sd = getweek(weekend.i)
  379.          say left(sd,13)" "left(games.i,4)"     "left(homew.i,3)"   "left(awayw.i,3)"     "left(draws.i,4)"     "left(losses.i,5)"     "left(goalss.i,5)
  380.       end
  381.    end
  382. end
  383. say
  384. say "-------------------------------------------------------------------------------"
  385.  
  386. exit
  387.  
  388. /* Procedure --------------------------------------------------------- */
  389.  
  390. getweek: procedure
  391. parse arg days
  392.  
  393. dd = days - 722450
  394. dd = date('n',dd,'i')
  395. dd = delstr(dd,8,2)
  396. return dd
  397.  
  398. /* ------------------------------------------------------------------- */